﻿
namespace NetROS.Tiers.Windows.Forms
{
	/// <summary>
	/// abstract _PostavkeServera typed datagridview
	/// </summary>
	[System.ComponentModel.DesignerCategoryAttribute("code")]
	public abstract class _PostavkeServeraDataGridViewBase : System.Windows.Forms.UserControl
	{	
		/// <summary> 
		/// Thrown when the current Entity changed.
		/// </summary>
		public event System.EventHandler<_PostavkeServeraDataGridViewEventArgs> CurrentEntityChanged;
		
		#region Fields
				
		/// <summary> 
		/// the current entity.
		/// </summary>
		private Entities._PostavkeServera _current_PostavkeServera = null;
		//private Dictionary<string, string> _columnsHeaders = new Dictionary<string, string>();
		
		/// <summary> 
		/// the datagridview instance
		/// </summary>
		protected System.Windows.Forms.DataGridView ux_PostavkeServeraDataGridView;
		
		/// <summary> 
		/// the errorprovider
		/// </summary>
		protected System.Windows.Forms.ErrorProvider ux_PostavkeServeraErrorProvider;
		
		/// <summary> 
		/// the bindingsource
		/// </summary>
		protected System.Windows.Forms.BindingSource ux_PostavkeServeraBindingSource;
		
		
		/// <summary> 
		/// the DGV column associated with the ID property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxIDDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the Parametar property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxParametarDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the ValueChar property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxValueCharDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the ValueInt property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxValueIntDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the ValueDate property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxValueDateDataGridViewColumn;
		
		#endregion
					
		#region Combo list
		
		#endregion
		
		#region Main Datasource
		
		private Entities.TList<Entities._PostavkeServera> __PostavkeServeraList;
				
		/// <summary> 
		/// The list of _PostavkeServera to be displayed in the DGV.
		/// </summary>
		[System.ComponentModel.Category("Data")]
		public Entities.TList<Entities._PostavkeServera> _PostavkeServeraList
		{
			get {return this.__PostavkeServeraList;}
			set
			{
				this.__PostavkeServeraList = value;
				this.ux_PostavkeServeraBindingSource.DataSource = null;
				this.ux_PostavkeServeraBindingSource.DataSource = value;
				this.ux_PostavkeServeraDataGridView.DataSource = null;
				this.ux_PostavkeServeraDataGridView.DataSource = this.ux_PostavkeServeraBindingSource;				
				//this.ux_PostavkeServeraBindingSource.ListChanged += new System.ComponentModel.ListChangedEventHandler(ux_PostavkeServeraBindingSource_ListChanged);
				this.ux_PostavkeServeraBindingSource.CurrentItemChanged += new System.EventHandler(On_PostavkeServeraBindingSourceCurrentItemChanged);
			}
		}
		
		private void On_PostavkeServeraBindingSourceCurrentItemChanged(object sender, System.EventArgs e)
		{
			_current_PostavkeServera = ux_PostavkeServeraBindingSource.Current as Entities._PostavkeServera;
			
			if (_current_PostavkeServera != null)
			{
				_current_PostavkeServera.Validate();
			}
			//__PostavkeServera.Validate();
			OnCurrentEntityChanged();
		}

		//void ux_PostavkeServeraBindingSource_ListChanged(object sender, System.ComponentModel.ListChangedEventArgs e)
		//{
			//throw new Exception("The method or operation is not implemented.");
		//}		
		
		#endregion
		
		/// <summary>
		/// Gets the currently selected <c cref="Entities._PostavkeServera"/> instance.
		/// </summary>
		public Entities._PostavkeServera Selected_PostavkeServera
		{
			get {return this._current_PostavkeServera;}
		}
		
		#region other properties
		
		/// <summary>
		/// Gets or sets a value indicating whether you have provided your own data-management operations for the DataGridView control.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool VirtualMode
		{
			get {return this.ux_PostavkeServeraDataGridView.VirtualMode;}
			set
			{
				this.ux_PostavkeServeraDataGridView.VirtualMode = value;
			}
		}
		
		/// <summary>
		/// Gets or sets a value indicating whether the option to add rows is displayed to the user.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool AllowUserToAddRows
		{
			get {return this.ux_PostavkeServeraDataGridView.AllowUserToAddRows;}
			set {this.ux_PostavkeServeraDataGridView.AllowUserToAddRows = value;}
		}
		
		/// <summary>
		/// Gets or sets a value indicating whether the user is allowed to delete rows from the DataGridView.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool AllowUserToDeleteRows
		{
			get {return this.ux_PostavkeServeraDataGridView.AllowUserToDeleteRows;}
			set {this.ux_PostavkeServeraDataGridView.AllowUserToDeleteRows = value;}
		}
		
		/// <summary>
		/// Gets the <c cref="DataGridView"/> instance.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public System.Windows.Forms.DataGridView DataGridView
		{
			get {return this.ux_PostavkeServeraDataGridView;}
		}
		
		/// <summary>
		/// Gets a collection that contains all the columns in the control.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]		
		[System.ComponentModel.DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Visible)]
		//[System.ComponentModel.EditorAttribute("System.Windows.Forms.Design.DataGridViewColumnCollectionEditor, System.Design", typeof(System.Drawing.Design.UITypeEditor))] 
		public System.Windows.Forms.DataGridViewColumnCollection Columns
		{
			get { return this.ux_PostavkeServeraDataGridView.Columns; }
		}
		
		#endregion
		
		/// <summary> 
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.IContainer components = null;
	
		/// <summary> 
		/// Clean up any resources being used.
		/// </summary>
		/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
		protected override void Dispose(bool disposing)
		{
			if (disposing && (components != null))
			{
				components.Dispose();
			}
			base.Dispose(disposing);
		}
	
		#region Constructor
	
		/// <summary>
		/// Initializes a new instance of the <see cref="_PostavkeServeraDataGridViewBase"/> class.
		/// </summary>
		public _PostavkeServeraDataGridViewBase()
		{			
			this.components = new System.ComponentModel.Container();			
			
			this.ux_PostavkeServeraDataGridView = new System.Windows.Forms.DataGridView();
			this.ux_PostavkeServeraBindingSource = new System.Windows.Forms.BindingSource(this.components);
			this.ux_PostavkeServeraErrorProvider = new System.Windows.Forms.ErrorProvider(this.components);
			this.uxIDDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxParametarDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxValueCharDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxValueIntDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxValueDateDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			((System.ComponentModel.ISupportInitialize)(this.ux_PostavkeServeraDataGridView)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.ux_PostavkeServeraBindingSource)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.ux_PostavkeServeraErrorProvider)).BeginInit();
			this.SuspendLayout();
						
			// 
			// ux_PostavkeServeraErrorProvider
			// 
			this.ux_PostavkeServeraErrorProvider.ContainerControl = this;
			this.ux_PostavkeServeraErrorProvider.DataSource = this.ux_PostavkeServeraBindingSource;						
			// 
			// ux_PostavkeServeraDataGridView
			// 
			this.ux_PostavkeServeraDataGridView.AutoGenerateColumns = false;
			this.ux_PostavkeServeraDataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
			this.ux_PostavkeServeraDataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
		this.uxIDDataGridViewColumn,
		this.uxParametarDataGridViewColumn,
		this.uxValueCharDataGridViewColumn,
		this.uxValueIntDataGridViewColumn,
		this.uxValueDateDataGridViewColumn			});
			this.ux_PostavkeServeraDataGridView.Dock = System.Windows.Forms.DockStyle.Fill;
			this.ux_PostavkeServeraDataGridView.Location = new System.Drawing.Point(0, 0);
			this.ux_PostavkeServeraDataGridView.Name = "ux_PostavkeServeraDataGridView";
			this.ux_PostavkeServeraDataGridView.Size = new System.Drawing.Size(470, 300);
			this.ux_PostavkeServeraDataGridView.TabIndex = 0;	
			this.ux_PostavkeServeraDataGridView.BackgroundColor = System.Drawing.Color.WhiteSmoke;
			this.ux_PostavkeServeraDataGridView.EnableHeadersVisualStyles = false;
			this.ux_PostavkeServeraDataGridView.DataError += new System.Windows.Forms.DataGridViewDataErrorEventHandler(this.On_PostavkeServeraDataGridViewDataError);
			this.ux_PostavkeServeraDataGridView.CellValueNeeded += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.On_PostavkeServeraDataGridViewCellValueNeeded);
			this.ux_PostavkeServeraDataGridView.CellValuePushed += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.On_PostavkeServeraDataGridViewCellValuePushed);
			
			//
			// uxIDDataGridViewColumn
			//
			this.uxIDDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxIDDataGridViewColumn.DataPropertyName = "ID";
			this.uxIDDataGridViewColumn.HeaderText = "ID";
			this.uxIDDataGridViewColumn.Name = "uxIDDataGridViewColumn";
			this.uxIDDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxIDDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxIDDataGridViewColumn.ReadOnly = false;		
			//
			// uxParametarDataGridViewColumn
			//
			this.uxParametarDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxParametarDataGridViewColumn.DataPropertyName = "Parametar";
			this.uxParametarDataGridViewColumn.HeaderText = "Parametar";
			this.uxParametarDataGridViewColumn.Name = "uxParametarDataGridViewColumn";
			this.uxParametarDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxParametarDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxParametarDataGridViewColumn.ReadOnly = false;		
			//
			// uxValueCharDataGridViewColumn
			//
			this.uxValueCharDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxValueCharDataGridViewColumn.DataPropertyName = "ValueChar";
			this.uxValueCharDataGridViewColumn.HeaderText = "ValueChar";
			this.uxValueCharDataGridViewColumn.Name = "uxValueCharDataGridViewColumn";
			this.uxValueCharDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxValueCharDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxValueCharDataGridViewColumn.ReadOnly = false;		
			//
			// uxValueIntDataGridViewColumn
			//
			this.uxValueIntDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxValueIntDataGridViewColumn.DataPropertyName = "ValueInt";
			this.uxValueIntDataGridViewColumn.HeaderText = "ValueInt";
			this.uxValueIntDataGridViewColumn.Name = "uxValueIntDataGridViewColumn";
			this.uxValueIntDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxValueIntDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxValueIntDataGridViewColumn.ReadOnly = false;		
			//
			// uxValueDateDataGridViewColumn
			//
			this.uxValueDateDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxValueDateDataGridViewColumn.DataPropertyName = "ValueDate";
			this.uxValueDateDataGridViewColumn.HeaderText = "ValueDate";
			this.uxValueDateDataGridViewColumn.Name = "uxValueDateDataGridViewColumn";
			this.uxValueDateDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxValueDateDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxValueDateDataGridViewColumn.ReadOnly = false;		
			
			// this
			this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
			this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
			this.Controls.Add(this.ux_PostavkeServeraDataGridView);
			this.Name = "_PostavkeServeraDataGridView";
			this.Size = new System.Drawing.Size(470, 300);
			((System.ComponentModel.ISupportInitialize)(this.ux_PostavkeServeraErrorProvider)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.ux_PostavkeServeraDataGridView)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.ux_PostavkeServeraBindingSource)).EndInit();
			this.ResumeLayout(false);
		}
		#endregion
				
		#region events
		
		/// <summary>
		/// Raised the CurrentEntityChanged event.
		/// </summary>
		protected void OnCurrentEntityChanged()
		{
			if (CurrentEntityChanged != null)
			{
				_PostavkeServeraDataGridViewEventArgs args = new _PostavkeServeraDataGridViewEventArgs();
				args._PostavkeServera = _current_PostavkeServera;
				CurrentEntityChanged(this, args); 
			}
		}
		
		#endregion
		
		/// <summary>
		/// Strongly typed event 
		/// </summary>
		public class _PostavkeServeraDataGridViewEventArgs : System.EventArgs
		{
			private Entities._PostavkeServera	__PostavkeServera;
	
			/// <summary>
			/// the  Entities._PostavkeServera instance.
			/// </summary>
			public Entities._PostavkeServera _PostavkeServera
			{
				get { return __PostavkeServera; }
				set { __PostavkeServera = value; }
			}	
		}
		
		/// <summary>
		/// Handles the DataError event of the ux_PostavkeServeraDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewDataErrorEventArgs"/> instance containing the event data.</param>
		protected void On_PostavkeServeraDataGridViewDataError(object sender, System.Windows.Forms.DataGridViewDataErrorEventArgs e)
		{
			System.Diagnostics.Debug.WriteLine(string.Format( "{0}, {1}", e.ColumnIndex, e.RowIndex));
		}
		
		/// <summary>
		/// Handles the CellValueNeeded event of the ux_PostavkeServeraDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewCellValueEventArgs"/> instance containing the event data.</param>
		protected void On_PostavkeServeraDataGridViewCellValueNeeded(object sender, System.Windows.Forms.DataGridViewCellValueEventArgs e)
		{
			switch(ux_PostavkeServeraDataGridView.Columns[e.ColumnIndex].Name)
			{
					case "uxIDDataGridViewColumn":
						e.Value = _PostavkeServeraList[e.RowIndex].ID;
						break;
					case "uxParametarDataGridViewColumn":
						e.Value = _PostavkeServeraList[e.RowIndex].Parametar;
						break;
					case "uxValueCharDataGridViewColumn":
						e.Value = _PostavkeServeraList[e.RowIndex].ValueChar;
						break;
					case "uxValueIntDataGridViewColumn":
						e.Value = _PostavkeServeraList[e.RowIndex].ValueInt;
						break;
					case "uxValueDateDataGridViewColumn":
						e.Value = _PostavkeServeraList[e.RowIndex].ValueDate;
						break;
				default:
				break;
			}
		}
		
		/// <summary>
		/// Handles the CellValuePushed event of the ux_PostavkeServeraDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewCellValueEventArgs"/> instance containing the event data.</param>
		protected void On_PostavkeServeraDataGridViewCellValuePushed(object sender, System.Windows.Forms.DataGridViewCellValueEventArgs e)
		{
			switch(ux_PostavkeServeraDataGridView.Columns[e.ColumnIndex].Name)
			{
					case "uxIDDataGridViewColumn":
						_PostavkeServeraList[e.RowIndex].ID = (System.Int32)e.Value;
						break;
					case "uxParametarDataGridViewColumn":
						_PostavkeServeraList[e.RowIndex].Parametar = (System.String)e.Value;
						break;
					case "uxValueCharDataGridViewColumn":
						_PostavkeServeraList[e.RowIndex].ValueChar = (System.String)e.Value;
						break;
					case "uxValueIntDataGridViewColumn":
						_PostavkeServeraList[e.RowIndex].ValueInt = (System.Int32?)e.Value;
						break;
					case "uxValueDateDataGridViewColumn":
						_PostavkeServeraList[e.RowIndex].ValueDate = (System.DateTime?)e.Value;
						break;
				default:
				break;
			}
		}
	}
}
